class TreeNode {
      int val;
      TreeNode left;
      TreeNode right;
      TreeNode() {}
      TreeNode(int val) { this.val = val; }
      TreeNode(int val, TreeNode left, TreeNode right) {
          this.val = val;
          this.left = left;
          this.right = right;
      }
  }


  //leetcode 2331 计算布尔二叉树的值
public class Test3 {
    public boolean evaluateTree(TreeNode root) {
        if (root == null) return true;
        if (root.left == null && root.right == null) {
            if (root.val == 0) return false;
            else return true;
        }
        boolean l = evaluateTree(root.left);
        boolean r = evaluateTree(root.right);
        if (root.val == 2) return l | r;
        else return l & r;
    }
}
